using UnityEngine;
using LFramework;
using TMPro;
using UnityEngine.UI;

public class UISceneLoadingWindow : UIWindow
{
    [SerializeField]
    private TextMeshProUGUI m_Desc;
    [SerializeField]
    private Image m_Progress;

    protected override void OnAwake()
    {
        base.OnAwake();
    }

    public override void Init()
    {
        base.Init();
        GameEntry.Event.CommonEvent.AddEventListener(EventType.UISceneLoadingProgressEvent, OnSceneLoadingProgress);
    }

    public override void Release()
    {
        base.Release();
        GameEntry.Event.CommonEvent.AddEventListener(EventType.UISceneLoadingProgressEvent, OnSceneLoadingProgress);
    }

    private void OnSceneLoadingProgress(object userData) 
    {
        VarFloat progressValue = (VarFloat)userData;

        m_Progress.fillAmount = progressValue;
        m_Desc.text = string.Format("加载进度：{0}/100",Mathf.FloorToInt(progressValue * 100));
    }
}
